package builder;

import java.io.*;

public class HTMLBuilder extends Builder {

    private String fileName;
    private PrintWriter printWriter;

    private StringBuilder html = new StringBuilder();

    public HTMLBuilder(String fileName) throws FileNotFoundException {
        this.fileName = fileName;
        File file = new File(this.fileName);
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        this.printWriter = new PrintWriter(fileOutputStream);
    }

    void makeTitle(String title) {
        html.append("<!DOCTYPE html>");
        html.append("<html lang=\"en\">");
        html.append("<head>");
        html.append("<meta charset=\"UTF-8\">");
        html.append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">");
        html.append("<meta http-equiv=\"X-UA-Compatible\" content=\"ie=edge\">");
        html.append("<title>" + title + "t</title>");
        html.append("</head>");
        html.append("<body>");
    }

    void makeString(String string) {
        html.append("<p>" + string + "</p>");
    }

    void makeItems(String[] items) {
        html.append("<ul>");
        for(int i = 0; i < items.length; i++){
            html.append("<li>" + items[i] + "</li>");
        }
        html.append("</ul>");
    }

    void close() {
        html.append("</body>");
        html.append("</html>");
        printWriter.write(html.toString());
        printWriter.flush();
        printWriter.close();
    }
}
